﻿@model  SDF.Plugin.Misc.SAPAdapter.Models.SAPClientSearchModel

@{
    //page title
    ViewBag.Title = T("Plugins.Misc.SAPAdapter.SAPInstance").Text;
    //active menu item (system name)
    //Html.SetActiveMenuItemSystemName("SAPAdapter");

    var defaultGridPageSize = EngineContext.Current.Resolve<SDF.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<SDF.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @T("Plugins.Misc.SAPAdapter.SAPInstance")
        </h1>
        <div class="pull-right">
            <a href="@Url.Action("Create")" class="btn bg-blue">
                <i class="fa fa-plus-square"></i>
                @T("Admin.Common.AddNew")
            </a>
        </div>
    </div>

    <div class="content">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default panel-search">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="col-md-4">
                                        @Html.SDFLabelFor(m => m.SAPInstance)
                                    </div>
                                    <div class="col-md-8">
                                        @Html.SDFEditorFor(m => m.SAPInstance)
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-7 col-md-offset-5">
                                <button type="button" id="search-btn" class="btn btn-primary btn-search">
                                    <i class="fa fa-search"></i>
                                    @T("Admin.Common.Search")
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="panel panel-default">
                    <div class="panel-body">
                        <div id="grid">
                            <script>
                                $(document).ready(function() {
                                    $("#grid").kendoGrid({
                                        dataSource: {
                                            type: "json",
                                            transport: {
                                                read: {
                                                    url: "@Html.Raw(Url.Action("Query", "SAPInstance"))",
                                                    type: "POST",
                                                    dataType: "json",
                                                    data: additionalData
                                                }
                                            },
                                            schema: {
                                                data: "Data",
                                                total: "Total",
                                                errors: "Errors"
                                            },
                                            error: function(e) {
                                                display_kendoui_grid_error(e);
                                                // Cancel the changes
                                                this.cancelChanges();
                                            },
                                            pageSize: @(defaultGridPageSize),
                                            serverPaging: true,
                                            serverFiltering: true,
                                            serverSorting: true
                                        },
                                        pageable: {
                                            refresh: true,
                                            pageSizes: [@(gridPageSizes)]
                                        },
                                        editable: {
                                            confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                            mode: "inline"
                                        },
                                        scrollable: false,
                                        columns: [
                                            {
                                                field: "CodeName",
                                                title: "@T("Plugins.Misc.SAPAdapter.SAPInstance.CodeName")"
                                            }, {
                                                field: "Name",
                                                title: "@T("Plugins.Misc.SAPAdapter.SAPInstance.Name")"
                                            }, {
                                                field: "ServerDisplay",
                                                title: "@T("Plugins.Misc.SAPAdapter.SAPInstance.ServerDisplay")"
                                            }, {
                                                field: "Id",
                                                title: " ",
                                                width: 180,
                                                attributes:{
                                                    style:"text-align:center"
                                                },
                                                template: '<a href="/SAP/SAPInstance/Edit?CodeName=#=CodeName#" class="btn bg-blue"><i class="fa fa-pencil-square-o"></i>@T("Admin.Common.Edit")</a> <a href="/SAP/SAPInstance/Delete/#=Id#" class="btn bg-red" onclick="return confirmDelete()"><i class="fa fa-trash-o"></i>@T("Admin.Common.Delete")</a>'
                                            }
                                        ]
                                    });
                                });
                            </script>

                            <script>
                                $(document).ready(function() {
                                    $('#search-btn').click(function() {
                                        var grid = $('#grid').data('kendoGrid');
                                        grid.dataSource.page(1); //new search. Set page size to 1
                                        //grid.dataSource.read(); we already loaded the grid above using "page" function

                                        return false;
                                    });

                                    $("".concat("#@Html.FieldIdFor(model => model.SAPInstance),",
                                    "#@Html.FieldIdFor(model => model.SAPInstance)")).keydown(function(event) {
                                        if (event.keyCode === 13) {
                                            $("#search-btn").click();
                                            return false;
                                        }
                                    });
                                });

                                function additionalData() {
                                    var data = {
                                        SAPInstance: $('#@Html.FieldIdFor(model => model.SAPInstance)').val(),
                                    };
                                    addAntiForgeryToken(data);
                                    return data;
                                }

                                function confirmDelete()
                                {
                                    return confirm('@T("Plugins.Misc.SAPAdapter.SAPInstance.DeleteConfirm").Text');
                                }
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}
